<?php
namespace Home\Controller;
use Think\Controller;
class ApplyController extends Controller 
{

    /*
    *添加信息
    */
    //http://www.mizhi.com/index.php/Home/Apply/add
    public function add()
    {


        if(IS_POST)
        {


            $model = D('apply');
            if($model->create(I('post.'), 1))     
            {
                $model->pubtime = time();
                if( false !== $model->add())     //插入之前添加 名字 uid
                {
                    $this->success('添加成功！', U('lst?p='.I('get.p')));
                    exit;
                }
            }
            $this->error($model->getError());
        }


        // 设置页面中的信息
        $this->assign(array(
            '_page_title' => '添加求职信息',
            '_page_btn_name' => '求职信息列表',
            '_page_btn_link' => U('lst'),
        ));



        $this->display();
    }

    //http://www.mizhi.com/index.php/Home/Apply/edit
    public function edit()
    {



        $aid = I('get.aid');

        if(IS_POST)    
        {         

            $model = D('apply');
            if($model->create(I('post.'), 2))
            {
                if($model->save() !== FALSE)
                {
                    $this->success('修改成功！', U('lst', array('p' => I('get.p', 1))));
                    exit;
                }
            }
            $this->error($model->getError());


        }
        $model = M('apply');
        $data = $model->find($aid);
        $this->assign('data', $data);

        // 设置页面中的信息
        $this->assign(array(
            '_page_title' => '修改求职信息',
            '_page_btn_name' => '求职信息列表',
            '_page_btn_link' => U('lst'),
        ));
        $this->display();
    }

    //http://www.mizhi.com/index.php/Home/Apply/delete
    public function delete()
    {

        $model = D('apply');
        echo 'delete  begin';
        if($model->delete(I('get.aid')) !== FALSE)
        {
            $this->success('删除成功！', U('lst', array('p' => I('get.p', 1))));
            exit;
        }
        else 
        {
                 
            $this->error($model->getError());
        }
    }

    //http://www.mizhi.com/index.php/Home/Apply/lst
    public function lst()
    {

        $model = D('apply');
        $data = $model->search();
        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));


        // 设置页面中的信息
        $this->assign(array(

            '_page_title' => '求职信息列表',
            '_page_btn_name' => '添加求职信息',
            '_page_btn_link' => U('add'),
        ));
        $this->display();
    }
    public function self(){
        $this->assign('name',cookie('username'));   
        $self = D('Apply');
        
        $self = D('User as a')->where("uname='".cookie('cname')."'")->join('Apply as b on a.uid=b.uid')->order('pubtime desc')->select();
        //print_r($self);
        
        //dump($self);
        $this->assign('self',$self[0]); 
        $this->display('self');
    }
}